package top.hepingan.java.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.hepingan.java.common.Result;
import top.hepingan.java.dto.MessageDto;
import top.hepingan.java.service.ChatService;

@RequestMapping("/chat")
@RestController
@Slf4j
@RequiredArgsConstructor
public class ChatController {

    private final ChatService chatService;


    //  发起聊天
    @GetMapping("/initiate")
    public Result initiate(Long userId) {
        return chatService.initiate(userId);
    }

    //  发送消息
    @PostMapping("/message")
    public Result message(@RequestBody MessageDto messageDto) {
        return chatService.message(messageDto);
    }

    //  获取聊天记录
    @GetMapping("/message/list")
    public Result messageList(@RequestParam Long id,@RequestParam Integer pageNum) {
        return chatService.messageList(id,pageNum);
    }

    //  获取会话列表
    @GetMapping("/list")
    public Result list() {
        return chatService.chatList();
    }


}
